package com.wedata.致远接口;

import cn.hutool.json.JSONObject;
import com.disdr.utils.LettuceRedis;
import com.wedata.HttpUtils;

/**
 * API文档地址：https://open.seeyoncloud.com/v5dev/72/784/801/803.html
 * API文档地址2：http://open.seeyon.com/book/ctp/restjie-kou/zu-zhi-mo-xing-guan-li.html
 * 生产环境，http://36.158.178.187:8089/seeyon，服务器在我们自己公司
 * 测试还借款
 */
public class token {

    /*测试账号*/
    /*public static String hostUrl = "http://192.168.15.6:10088/seeyon";
    public static Long accountId = 670869647114347L;
    private static String secret = "73b05f45-546f-4dc9-90cb-0260fc4be4c8";*/


    /**
     * 生产账号
     */
    public static String hostUrl = "http://36.158.178.187:8089/seeyon";
    public static Long accountId = 670869647114347L;
    private static String secret = "e431b090-027d-44cf-a0f9-99f96a6ea00c";

    public static void main(String[] args) {
        System.out.println(getToken());
    }

    /**
     * 获取token
     * @return
     */
    public static String getToken(){
        String token = LettuceRedis.get("wegym:致远:token");
        if(token==null){
            //JSONObject result = HttpUtils.doGet("http://36.158.178.187:8089/seeyon/rest/token/wedatacenter/e431b090-027d-44cf-a0f9-99f96a6ea00c?loginName=HRadmin");
            //JSONObject result = HttpUtils.doGet(hostUrl+"/rest/token/wedatacenter/73b05f45-546f-4dc9-90cb-0260fc4be4c8?loginName=HRadmin");
            JSONObject result = HttpUtils.doGet(hostUrl+"/rest/token/wedatacenter/"+ secret +"?loginName=HRadmin");
            System.out.println(result);
            //return result.getJSONObject("bindingUser").getStr("sessionId");
            token = result.getStr("id");
            LettuceRedis.setExpire("wegym:致远:token",token,15*60);
            return token;
        }else{
            return token;
        }

        //{"bindingUser":{"loginState":"logging","sessionId":"1D862477D0CB54F8FDA51C5C2AF45089","id":807790925431784773,"securityKey":0,"loginName":"HRadmin","name":"HRadmin","loginAccount":670869647114347,"loginAccountName":"健萌体育产业发展集团有限公司","loginAccountShortName":"单位","province":null,"city":null,"rectangle":null,"nodeIndex":"","departmentId":7865049063101582058,"levelId":-6814540232295297094,"postId":-6288855375122315150,"accountId":670869647114347,"remoteAddr":"42.48.17.226","userAgentFrom":"iphone","externalType":0,"locale":"zh_CN","loginTimestamp":1710482246000,"loginLogId":null,"skin":"default","userSSOFrom":null,"browser":null,"timeZone":"Asia/Shanghai","canSendSMS":false,"etagRandom":"-898910047","changeRoleTimestamp":0,"internal":true,"systemAdmin":false,"auditAdmin":false,"platformAdmin":false,"superAdmin":false,"administrator":false,"groupAdmin":false,"v5External":false,"admin":false,"v5Member":true,"visitor":false,"loginSign":2,"vjoinMember":false,"defaultGuest":false,"guest":false,"screenGuest":false,"fromM1":true},"userName":"wedatacenter","id":"12d506d6-3ce3-4572-ad42-6672484eb8c7"}
        //{"bindingUser":{"loginState":"logging","sessionId":"4909E502A5BC659A4FC06D6D23936000","id":807790925431784773,"securityKey":0,"loginName":"HRadmin","name":"HRadmin","loginAccount":670869647114347,"loginAccountName":"健萌体育产业发展集团有限公司","loginAccountShortName":"单位","province":null,"city":null,"rectangle":null,"nodeIndex":"","departmentId":7865049063101582058,"levelId":-6814540232295297094,"postId":-6288855375122315150,"accountId":670869647114347,"remoteAddr":"42.48.17.226","userAgentFrom":"iphone","externalType":0,"locale":"zh_CN","loginTimestamp":1710484609563,"loginLogId":null,"skin":"default","userSSOFrom":null,"browser":null,"timeZone":"Asia/Shanghai","canSendSMS":false,"etagRandom":"-439874749","changeRoleTimestamp":0,"internal":true,"systemAdmin":false,"auditAdmin":false,"platformAdmin":false,"superAdmin":false,"administrator":false,"groupAdmin":false,"v5External":false,"admin":false,"v5Member":true,"visitor":false,"loginSign":2,"vjoinMember":false,"defaultGuest":false,"guest":false,"screenGuest":false,"fromM1":true},"userName":"wedatacenter","id":"38d9e9ac-d9bb-4424-889d-77e368f621c4"}
        //{"bindingUser":{"loginState":"logging","sessionId":"27D9364E05BA4AF22FA3BAEFB50FA089","id":807790925431784773,"securityKey":0,"loginName":"HRadmin","name":"HRadmin","loginAccount":670869647114347,"loginAccountName":"健萌体育产业发展集团有限公司","loginAccountShortName":"单位","province":null,"city":null,"rectangle":null,"nodeIndex":"","departmentId":7865049063101582058,"levelId":-6814540232295297094,"postId":-6288855375122315150,"accountId":670869647114347,"remoteAddr":"42.48.17.226","userAgentFrom":"iphone","externalType":0,"locale":"zh_CN","loginTimestamp":1710495663173,"loginLogId":null,"skin":"default","userSSOFrom":null,"browser":null,"timeZone":"Asia/Shanghai","canSendSMS":false,"etagRandom":"168998844","changeRoleTimestamp":0,"internal":true,"systemAdmin":false,"auditAdmin":false,"platformAdmin":false,"superAdmin":false,"administrator":false,"groupAdmin":false,"v5External":false,"admin":false,"v5Member":true,"visitor":false,"loginSign":2,"vjoinMember":false,"defaultGuest":false,"guest":false,"screenGuest":false,"fromM1":true},"userName":"wedatacenter","id":"194e824e-138f-409b-9443-a0c0968f1f75"}
    }

}
